from direct.fsm import FSM

class GameFSM(FSM.FSM):
  nextState = {
      ('Welcome', 'proceed') : 'Question',
      ('Question', 'correct') : 'CorrectAnswer',
      ('Question', 'wrong') : 'WrongAnswer',
      ('CorrectAnswer', 'proceed') : 'Question',
      ('CorrectAnswer', 'quit') : 'Quit',
      ('WrongAnswer', 'proceed') : 'Question',
      ('WrongAnswer', 'quit') : 'Quit',  #Maybe have a more spectacular ending here?
  }

  def __init__(self, world):
    FSM.FSM.__init__(self,"")
    
    
    self.accept('proceed', self.choice_handler, ['proceed'])
    self.accept('correct', self.choice_handler, ['correct'])
    self.accept('wrong', self.choice_handler, ['wrong'])
    self.accept('quit', self.choice_handler, ['quit'])
    
    
    self.world = world
    
    self.request('Welcome')

    
  def choice_handler(self, arg):
    self.request(arg)

  def defaultFilter(self, request, args):
    key = (self.state, request)
    return self.nextState.get(key)



  def enterWelcome(self):
    #print "entering welcome"
    self.world.doWelcome()

  def enterQuestion(self):
    #print "entering question"
    self.world.doQuestion()
    
  def enterCorrectAnswer(self):
    #print "entering correctAnswer"
    self.world.doCorrectAnswer()
  
  def enterWrongAnswer(self):
    #print "entering wrongAnswer"
    self.world.doWrongAnswer()
    